/* eslint valid-jsdoc: "off" */

'use strict';

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = exports = {};

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1592221899640_7362';

  // add your middleware config here
  config.middleware = [ 'auth' ];

  config.session = {
    key: 'lkjsf&7238sHS*fs12DA', // 设置session cookie里面的key
    maxAge: 24 * 3600 * 1000, // 1 day
    httpOnly: true,
    encrypt: true,
    renew: true, // renew等于true 那么每次刷新页面的时候 session都会被延期
  };

  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
    initialization: false,
    jwt: {
      secret: 'aksd92398fsdASd12$%hk',
    },
    view: {
      defaultViewEngine: 'nunjucks',
      mapping: {
        '.tpl': 'nunjucks',
      },
    },
    sequelize: {
      dialect: 'mysql',
      host: '127.0.0.1',
      port: 3306,
      username: 'root',
      password: 'Jspt1024',
      database: 'eggadmin_development',
      logging: true,
    },
    multipart : {
      fileSize: '10mb',
      model: 'stream',
      fileExtensions: ['.xls', '.xlsx', '.txt', '.jpg', '.jpeg', '.png', '.gif']
    },
    account: {
      secretStr: '92jSjkf*&34hjsfasdf;wDGer', // 安全字符，用于账号密码加密
    },
    auth: {
      whiteUrls: [ // 无需登陆验证的Url，用于中间件auth
        '/init', '/sysInit', '/login', '/register', '/userLogin', '/userRegister', '/userLogout', '/getCode', '/error', '/public',
      ],
      passport: {
        type: 'jwt', // session || jwt
        jwtSecret: 'aksd92398fsdASd12$%hk',
      },
    },
    validate: {
      convert: true,
      // validateRoot: false,
    },
    // security: { // 如果开启跨域，需关闭crsf校验
    //   csrf: false,
    //   domainWhiteList: [ 'http://localhost:8080' ],
    // },
    // cors: {
    //   // 不能写*
    //   origin: 'http://localhost:8080',
    //   allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH',
    //   // 该属性允许cookie跨域
    //   credentials: true,
    // },
    // ajax访问需添加属性： xhrFields: { withCredentials: true }
  };

  return {
    ...config,
    ...userConfig,
  };
};
